package com.panopset.gui.selection;

import static com.panopset.Util.*;

import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.JToggleButton;

import com.panopset.gui.container.TitledPanel;

/**
 * Selection group.
 *
 * @author Karl Dinwiddie
 *
 */
public class SelectionGroup extends TitledPanel {

    /**
     * Selection panel.
     */
    private final SelectionPanel o;

    /**
     * Constructor.
     *
     * @param selectionPanel
     *            Selection panel.
     * @param title
     *            Title.
     * @param toolTipText
     *            Tool tip text.
     * @param nvp
     *            Name value pair arrays.
     * @param isSingleSelectionOnly
     *            true if single selection only (radio buttons)
     */
    public SelectionGroup(final SelectionPanel selectionPanel,
            final String title, final String toolTipText, final String[][] nvp,
            final boolean isSingleSelectionOnly) {
        super(title, new FlowLayout(), toolTipText);
        this.o = selectionPanel;
        setLayout(new FlowLayout());
        for (String[] s : nvp) {
            JToggleButton btn = null;
            if (isSingleSelectionOnly) {
                btn = new JRadioButton(s[0]);
            } else {
                btn = new JCheckBox(s[0]);
            }
            btn.setFont(ARIAL_PLAIN_9);
            btn.setBackground(Color.WHITE);
            o.getToggleButtons().add(btn);
            btn.addActionListener(o);
            o.getSelections().put(s[0], s[1]);
            add(btn);
        }
    }

    /**
     * Serial version id.
     */
    private static final long serialVersionUID = VERSION_SERIAL_NUMBER;
}
